/**
 * @param {number} m
 * @param {number} n
 * @param {number} k
 * @return {number}
 */
 var movingCount = function(m, n, k) {
    let arr=new Array(m).fill(0).map(()=>new Array(n).fill(false));
    let res=0;
    dfs(0,0)
    return res;
    function dfs(row,col){
        if(row>=m || col >=n || arr[row][col] || sum(row,col)>k ){
            return ;
        }
        res++;
        arr[row][col]=true;
        dfs(row+1,col);
        dfs(row,col+1);
    }
    function sum(row,col){
        let sum=0;
        while(row!=0){
            sum+=row%10;
            row=Math.floor(row/10);
        }
        while(col!=0){
            sum+=col%10;
            col=Math.floor(col/10);
        }
        return sum;
    }
};